package com.restlet.spike.resource;

import org.restlet.data.MediaType;
import org.restlet.data.Response;
import org.restlet.data.Request;
import org.restlet.resource.*;
import org.restlet.Context;

public class OrderResource extends Resource {

    private String user;
    private String order;

    public OrderResource(Context context, Request request, Response response) {
        super(context, request, response);
        user = (String) request.getAttributes().get("user");
        order = (String) request.getAttributes().get("order");
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
    }

    @Override
    public Representation represent(Variant variant) throws ResourceException {
        String message = String.format("order [%s] of user [%s]", order, user);
        Representation representation = new StringRepresentation(message, MediaType.TEXT_PLAIN);
        return representation;
    }
}